package cn.iocoder.devlop.module.annual.report.common.controller;

import cn.hutool.json.JSONObject;
import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.common.service.EnttypeAntypeService;
import cn.iocoder.devlop.module.annual.report.common.service.SyncInfoService;
import cn.iocoder.devlop.module.annual.report.common.vo.ChangeInfoNotificationVo;
import cn.iocoder.devlop.module.annual.report.enums.ChangeInfoNotificationEnum;
import cn.iocoder.devlop.module.infra.util.ConfigUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

/**
 * 公共接口
 *
 * @author Euan
 * @since 2024/1/18
 */
@Tag(name = "服务通用接口")
@RestController
@RequestMapping("/app-api/common")
@RequiredArgsConstructor
public class CommonController {

    private final SyncInfoService syncInfoService;

    private final EnttypeAntypeService enttypeAntypeService;

    @Operation(summary = "通知变更信息")
    @PostMapping("/change-info-notification")
    public CommonResult<String> changeInfoNotification(@Valid @RequestBody ChangeInfoNotificationVo changeInfoNotificationVo) {
        ChangeInfoNotificationEnum.Type type = ChangeInfoNotificationEnum.Type.getType(changeInfoNotificationVo.getType());
        ChangeInfoNotificationEnum.Target target = ChangeInfoNotificationEnum.Target.getTarget(changeInfoNotificationVo.getTarget());
        syncInfoService.syncNotification(type, target, changeInfoNotificationVo.getData());
        return success("数据同步完成");
    }

    @Operation(summary = "获取配置信息")
    @GetMapping("/get-config")
    public CommonResult<JSONObject> getConfig(@RequestParam("enttype")String enttype) {
        return success(enttypeAntypeService.getJson(enttype));
    }

    @Operation(summary = "获取咨询热线")
    @GetMapping("/get-consultation-hotline")
    @PermitAll
    public CommonResult<String> getConsultationHotline(){
        return success(ConfigUtils.getConfigByKey("consultation_hotline"));
    }




}
